//
//  HZNoticeTableViewCell.m
//  HZTC_YaDeArt
//
//  Created by MayerF on 17/3/25.
//  Copyright © 2017年 HZTC. All rights reserved.
//

#import "HZNoticeTableViewCell.h"

#define kOwnedStockNameFont [UIFont systemFontOfSize:15]
#define kOwnedStockCodeFont [UIFont systemFontOfSize:13]
#define kUpDownMargin 5
#define kLeftRightMargin 10
#define kDateW 100

@interface HZNoticeTableViewCell()
@property (nonatomic, strong)UILabel *pTitleLabel;
@property (nonatomic, strong)UILabel *pDateLabel;
@end

@implementation HZNoticeTableViewCell

+ (HZNoticeTableViewCell *)leftCellTableView:(UITableView *)tableView
                                   indexPath:(NSIndexPath *)indexPath
                                   cellModel:(HZNoticeModel *)cellModel
                                   cellHight:(CGFloat)cellHight
{
    return [self leftCellTableView:tableView indexPath:indexPath cellModel:cellModel cellHight:cellHight cellW:0];
}

+ (HZNoticeTableViewCell *)leftCellTableView:(UITableView *)tableView
                                   indexPath:(NSIndexPath *)indexPath
                                   cellModel:(HZNoticeModel *)cellModel
                                   cellHight:(CGFloat)cellHight
                                       cellW:(CGFloat)cellW
{
    return [[self alloc] initWithTableView:tableView indexPath:indexPath cellModel:cellModel cellHight:cellHight cellW:cellW];
}


- (HZNoticeTableViewCell *)initWithTableView:(UITableView *)tableView
                                    indexPath:(NSIndexPath *)indexPath
                                    cellModel:(HZNoticeModel *)cellModel
                                    cellHight:(CGFloat)cellHight
                                        cellW:(CGFloat)cellW
{
    static NSString *ID = @"noticeCell";
    HZNoticeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[HZNoticeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        [cell p_commonInit];
    }
    [cell p_updateDataWithmodel:cellModel indexPath:indexPath cellH:cellHight cellW:cellW];
    
    return cell;
}

- (void)p_commonInit
{
    _pTitleLabel = [UILabel new];
    _pDateLabel = [UILabel new];
    _pTitleLabel.font = kOwnedStockNameFont;
    _pDateLabel.font = kOwnedStockCodeFont;
    _pDateLabel.textAlignment = NSTextAlignmentRight;
    _pDateLabel.textColor = kMYHexToRGB(0xf15059, 1);
    _pTitleLabel.numberOfLines = 0;
    self.backgroundColor = [UIColor whiteColor];
    
    [self.contentView addSubview:_pTitleLabel];
    [self.contentView addSubview:_pDateLabel];
}

- (void)p_updateDataWithmodel:(HZNoticeModel *)model indexPath:(NSIndexPath *)indexPath cellH:(CGFloat)cellH cellW:(CGFloat)cellW
{
    [self p_cleaOldData];
    [self p_updateNewData:model];
    [self p_updateFrame:cellH cellW:cellW];
}

- (void)p_updateNewData:(HZNoticeModel *)model
{
    _pTitleLabel.text = model.notice_title;
    _pDateLabel.text = model.publish_date;
}

- (void)p_updateFrame:(CGFloat)cellH cellW:(CGFloat)cellW
{
    if (cellW == 0) {
        cellW = kScreenW;
    }
    CGFloat fItemW = cellW - 2*kLeftRightMargin;
    CGFloat fItemH = (cellH - 2*kUpDownMargin)/2;
    
    _pTitleLabel.frame = CGRectMake(kLeftRightMargin, kUpDownMargin, fItemW, fItemH);
    _pDateLabel.frame = CGRectMake(cellW - kLeftRightMargin - kDateW, cellH - kUpDownMargin - 20, kDateW, 20);
}

- (void)p_cleaOldData
{
    [_pTitleLabel setText:@""];
    [_pDateLabel setText:@""];
    
}


@end
